<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 300px;
            height: 30px;
            display: flex;
            position: relative;
        }
        input{
            width: 100%;
            height: 100%;
            border:none;
            border-bottom: 1px solid gray;
            outline: none;
            padding: 10px;
        }
        label{
            width: 20px;
            height: 20px;
            position: absolute;
            top:0;
            right: 32px;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <div>
        <label for="" >
            <img src="./close.png" alt="" class="eye">
        </label>
        <input type="password" class="pwd">
    </div>
    <script>
        // var flag = 0 
        var eye = document.querySelector('.eye')
        var inputEle = document.querySelector('.pwd')
        eye.onclick = function(){
            if(inputEle.type === 'password'){
            inputEle.type  = 'text';
            this.src = './open.png';
            // flag = 1;
        }else{
            inputEle.type = 'password';
            this.src = './close.png'
        }
        }
    </script>
</body>
</html>